package com.bilin.coin.activity;

import android.view.View;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bilin.coin.R;
import com.bilin.coin.bean.BiLinWallet;
import com.bilin.coin.bean.GoldBeanWrag;
import com.bilin.coin.bean.MyStarDataBean;
import com.bilin.coin.bean.MyStarDataNextBean;
import com.bilin.coin.common.base.BaseAppCompatActivity;
import com.bilin.coin.tools.AbsHeadRecycleViewActivity;
import com.bilin.coin.tools.Geter;
import com.bilin.coin.utils.GsonUtil;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Route(path = "/auction/MyTeamActivity")
public class MyTeamActivity extends AbsHeadRecycleViewActivity<MyStarDataNextBean.RecordsBean> {
    @Override
    protected void initView() {
        super.initView();
        setTitle("我的团队");
        getWallet();
    }

    @Override
    protected void convertItem(BaseViewHolder helper, MyStarDataNextBean.RecordsBean item) {
        helper.setText(R.id.tv_phone,item.getLoginName());

        helper.setText(R.id.tv_jx_team,"团队绩效积分:"+item.getContribution());
        helper.setText(R.id.tv_jx_xq,"小区绩效积分:"+item.getSlaveContribution());

        helper.setText(R.id.tv_time_reg,"注册时间:"+item.getCreateTime());
        helper.setText(R.id.tv_num,"团队 "+item.getTotalSpreadNum()+"人");
        TextView tv_real = helper.getView(R.id.tv_real);
        tv_real.setVisibility(item.isHasKyc()?View.VISIBLE:View.GONE);

    }



    @Override
    protected int fillItemLayout() {
        return R.layout.item_my_team;
    }

    @Override
    public int fillPageSize() {
        return 10;
    }

    @Override
    public boolean isPost() {
        return false;
    }

    @Override
    public String fillUrl() {
        return "/api/bl-level/getMyChildData";
    }

    private void getWallet() {
        new Geter(this, false, true) {
            @Override
            protected String fillUrl() {
                return "/api/bl-level/getMyData";
            }

            @Override
            protected Map<String, String> fillParams() {
                return new HashMap<>();
            }

            @Override
            protected void disposeSuccess(String dataJson) {
                super.disposeSuccess(dataJson);
                MyStarDataBean myStarDataBean = GsonUtil.GsonToBean(dataJson, MyStarDataBean.class);
                fillData(myStarDataBean);
            }
        };
    }

    private void fillData(MyStarDataBean myStarDataBean) {
        tv_level.setText(myStarDataBean.getLevelName());
        tv_team_num.setText(myStarDataBean.getTotalSpreadNum());
        tv_jx.setText(myStarDataBean.getContribution());
        tv_jx_xq.setText(myStarDataBean.getSlaveContribution());
        tv_jx_dq.setText(myStarDataBean.getMasterContribution());
        tv_d_num.setText(myStarDataBean.getDirectNum()+"/"+myStarDataBean.getDirectNumValid());
    }

    TextView tv_level;
    TextView tv_team_num;
    TextView tv_jx;
    TextView tv_jx_xq;
    TextView tv_jx_dq;
    TextView tv_d_num;

    @Override
    protected View fillHeadView() {
        View view = View.inflate(this,R.layout.head_my_team, null);
        tv_level = view.findViewById(R.id.tv_level);
        tv_team_num = view.findViewById(R.id.tv_team_num);
        tv_jx = view.findViewById(R.id.tv_jx);
        tv_jx_xq = view.findViewById(R.id.tv_jx_xq);
        tv_jx_dq = view.findViewById(R.id.tv_jx_dq);
        tv_d_num = view.findViewById(R.id.tv_d_num);
        view.findViewById(R.id.iv_more).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                jumpArticle("4","详情");
            }
        });
        return view;
    }

    @Override
    public Map<String, String> fillParams() {
        HashMap params = new HashMap();
        params.put("currentPage", page + "");
        params.put("pageSize", pageSize + "");
        return params;
    }

    @Override
    public List<MyStarDataNextBean.RecordsBean> parseListDataAndFillTotal(String dataJson) {
        MyStarDataNextBean goldBeanWrag = GsonUtil.GsonToBean(dataJson, MyStarDataNextBean.class);
        totalCount = goldBeanWrag.getTotal();
        return goldBeanWrag.getRecords();
    }

    @Override
    protected void initData() {

    }


    @Override
    protected void refreshFragmentOrHead() {
        getWallet();
    }

}
